<%-- 
    Document   : usl
    Created on : Dec 20, 2011, 10:45:07 AM
    Author     : administrator
--%>

<%@page errorPage="/pages/error.jsp" contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<f:view locale="#{languagesBean.locale}">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><h:outputText value="#{lang.uslTitle}" /></title>
        </head>
        <body>
            <jsp:include page="/pages/header.jsp"/>
            
            <rich:tabPanel style="margin-left:auto; margin-right:auto;" width="80%" headerAlignment="right" selectedTab="toremindvisits" >
                <rich:tab id="allpatients" label="#{lang.uslPatHeader}" action="#{patientList.allPatients()}">
                    <a4j:form>
                        <rich:dataTable value="#{patientList.patientList}" var="singlepatient" rows="20" width="100%">
                            
                            
                            <f:facet name="caption">
                                <h:outputText value="#{lang.uslPatCaption}" />
                            </f:facet>
                            
                            
                            <f:facet name="header">
                                <h:outputText value="#{lang.uslPatHeader}" />
                            </f:facet>
                            
                            <rich:column sortBy="#{singlepatient.id}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatId}"/>
                                </f:facet>
                                <a4j:commandLink value="#{singlepatient.id}" action="#{patient.retrievePatient()}">
                                    <f:setPropertyActionListener target="#{patient.id}" value="#{singlepatient.id}"/>
                                    <f:setPropertyActionListener target="#{patient.refDoctorId}" value="#{singlepatient.refDoctorId}"/>
                                    <f:setPropertyActionListener target="#{patient.callerId}" value="#{singlepatient.refDoctorId}"/>
                                </a4j:commandLink>
                            </rich:column>
                            
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatPhoto}"/>
                                </f:facet>
                                <h:graphicImage value="#{singlepatient.picture}" width="50" height="50"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatName}"/>
                                </f:facet>
                                <h:outputText value="#{singlepatient.name}"/>
                            </rich:column>
                            
                            <rich:column sortBy="#{singlepatient.surname}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatSurname}"/>
                                </f:facet>
                                <h:outputText value="#{singlepatient.surname}"/>
                            </rich:column>
                            
                            <rich:column sortBy="#{singlepatient.birthdate}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatBirthdate}"/>
                                </f:facet>
                                <h:outputText value="#{singlepatient.birthdate}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatParent}"/>
                                </f:facet>
                                <h:outputText value="#{singlepatient.parentId}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslPatDoc}"/>
                                </f:facet>
                                <h:outputText value="#{singlepatient.refDoctorId}"/>
                            </rich:column>
                            
                            
                            <f:facet name="footer">
                                <rich:datascroller id="scroller" ></rich:datascroller>
                            </f:facet>
                            
                        </rich:dataTable>                        
                    </a4j:form>
                </rich:tab>
                
                <rich:tab id="toremindvisits" label="#{lang.uslNextVisHeader}" action="#{visitList.toRemindVisits()}"> 
                    <f:setPropertyActionListener target="#{visitList.callingDoctorId}" value="#{user.id}"/> 
                    <h:outputText value="#{user.id}"/>
                    
                    <a4j:form id="form">
                    
                        
                        <h:selectOneRadio value="#{visitList.allReminders}">
                            <f:selectItem itemLabel="#{lang.uslNextVisAllRem}" itemValue="true" />
                            <f:selectItem itemLabel="#{lang.uslNextVisNotNeglRem}" itemValue="false" />
                            <a4j:support event="onchange" action="#{visitList.toRemindVisits()}" reRender="form"/>
                        </h:selectOneRadio>
                        
                        <rich:panel rendered="#{visitList.allReminders}">
                            <h:outputText value="#{lang.uslNextVisInterval}"/>
                            <h:inputText value="#{visitList.interval}"/>  
                            <a4j:support event="onchange" action="#{visitList.toRemindVisits()}" reRender="form"/>
                        </rich:panel>
                        
                        
                        <rich:dataTable value="#{visitList.visitList}" var="visit" rows="20" width="100%" rendered="#{visitList.interval > 0 && visitList.allReminders}">
                            
                            
                            <f:facet name="caption">
                                <h:outputText value="#{lang.uslNextVisCaption}" />
                            </f:facet>
                            
                            
                            <f:facet name="header">
                                <h:outputText value="#{lang.uslNextVisHeader}" />
                            </f:facet>
                            
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisId}"/>
                                </f:facet>
                                <h:outputText value="#{visit.visit_id}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisDate}"/>
                                </f:facet>
                                <h:outputText value="#{visit.date}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisType}"/>
                                </f:facet>
                                <h:outputText value="#{visit.type}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisPatName}"/>
                                </f:facet>
                                <%-- Link al Paziente --%>
                                <a4j:commandLink value="#{visit.patient_id}" action="#{patient.retrievePatient()}">
                                    <f:setPropertyActionListener target="#{patient.id}" value="#{visit.patient_id}"/>
                                    <f:setPropertyActionListener target="#{patient.refDoctorId}" value="#{visit.doctor_id}"/>
                                    <f:setPropertyActionListener target="#{patient.callerId}" value="#{visit.doctor_id}"/>
                                </a4j:commandLink>                              
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisMedName}"/>
                                </f:facet>
                                <h:outputText value="#{visit.doctor_name}"/>
                            </rich:column>                            
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.uslNextVisReminder}"/>
                                </f:facet>
                                <h:outputText value="#{visit.reminder}"/>
                            </rich:column>
                            
                            <f:facet name="footer">
                                <rich:datascroller id="scroller"></rich:datascroller>
                            </f:facet>
                            
                        </rich:dataTable>  
                        
                        <a4j:commandButton value="#{lang.uslNextVisConfirm}" action="#{visitList.remindVisits(user.id)}" reRender="form"/>
                    </a4j:form>
                </rich:tab>
                
                <%-- REGISTER PATIENT TAB --%>
                <rich:tab id="RegisterTab" label="#{lang.doctorRegHeader}" action="#{patient.blankPatient()}">
                                        
                    <a4j:form>
                        <rich:panel id="registerPanel" header="#{lang.doctorRegHeader}"  style="text-align:justify; height:100%; width:100%;">                       
                            <p>
                                <h:outputText value="#{lang.doctorRegName} " />                            
                                <h:inputText value="#{patient.name}"/>
                                
                                <h:outputText value="#{lang.doctorRegSurname} " />
                                <h:inputText value="#{patient.surname}"/>
                            </p>
                            <p>
                                <h:selectOneRadio id="gender" label="#{lang.doctorRegGender}" value="#{patient.gender}">
                                    <f:selectItem id="M" itemLabel="M" itemValue="M" />
                                    <f:selectItem id="F" itemLabel="F" itemValue="F" />
                                </h:selectOneRadio>
                            </p>
                            
                            <h:outputText value="#{lang.doctorRegBirthDate} " />
                            <rich:calendar id="date" value="#{patient.calendarBirthdate}"/>
                            <%-- Aggiungere selettore per anno se possibile --%>
                            
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegBirthPlace} " />
                            <h:inputText value="#{patient.birthplace}"/>
                            
                            <h:outputText value="#{lang.doctorRegAddress} " />
                            <h:inputText value="#{patient.address}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegCAP} " />
                            <h:inputText value="#{patient.cap}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegEmail} " />
                            <h:inputText value="#{patient.email}" />
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegParentUsername} " />
                            <h:inputText value="#{patient.parentId}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegCell} " />
                            <h:inputText value="#{patient.phone}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegChiefTain} " />
                            <h:inputText value="#{patient.chiefTainId}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegPictures} " />
                            <%-- Upload Picture --%>
                            <rich:simpleTogglePanel opened="false" value="Upload #{lang.doctorRegPictures}" width="50%">
                                <rich:fileUpload                    
                                    fileUploadListener="#{patient.uploadListener}"
                                    maxFilesQuantity="1"
                                    immediateUpload="true"
                                    acceptedTypes="jpg, gif, png, bmp"
                                    />
                            </rich:simpleTogglePanel>
                            <br>
                            
                            <p>
                                <h:selectOneMenu id="type" value="#{patient.refDoctorId}">
                                    <f:selectItem itemLabel="Piero Zambraga" itemValue="2" />
                                    <f:selectItem itemLabel="Silvia Arcuri" itemValue="3" />
                                    <f:selectItem itemLabel="Agatino Mazzi" itemValue="4" />
                                    <f:selectItem itemLabel="Penelope Greco" itemValue="5" />
                                    <f:selectItem itemLabel="Edilio Pagnotto" itemValue="6" />
                                </h:selectOneMenu>                                
                            </p>
                            
                            <%-- Messages --%>
                                <h:outputText value="#{lang.doctorRegSuccess}" rendered="#{patient.registrationCompleted}" style="color:green; font-size:14px;"/><BR>
                                <h:outputText value="#{lang.doctorRegFail}" rendered="#{patient.registrationFailed}" style="color:red; font-size:14px;"/><BR>
                            
                            <a4j:commandButton value="#{lang.doctorRegRegisterAction}" action="#{patient.registerPatient()}"/>
                        </rich:panel>
                    </a4j:form>
                </rich:tab>
                
            </rich:tabPanel>
            
        </body>
    </html>
</f:view>
